package com.yanqu.road.server.cmd.guess.group;

import com.yanqu.road.exception.BusinessException;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.CommonGuessProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.guess.CrossCommonGuessMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.C2_COMMON_GUESS_GET_REWARD_LIST_GROUP, desc = "通用竞猜-获取奖励数据-商会分组活动")
public class CrossCommonGuessGetRewardListGroupCmd extends CrossUnionCommand {

    private long playerId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        playerId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CommonGuessProto.CommonGuessRewardListReqMsg reqMsg = CommonGuessProto.CommonGuessRewardListReqMsg.parseFrom(packet.getBytes());
        CommonGuessProto.CommonGuessRewardListRespMsg.Builder respMsg;
        try {
            respMsg = CrossCommonGuessMgr.getRewardList(packet.getPlayerId(), groupId, reqMsg);
        } catch (BusinessException e) {
            respMsg = CommonGuessProto.CommonGuessRewardListRespMsg.newBuilder();
            respMsg.setRet(e.getCode());
        }
        MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_COMMON_GUESS_GET_REWARD_LIST, respMsg));
    }

    @Override
    public void sendData() {

    }
}
